package com.controller;

import com.Dto.AllCounselorInfoDto;
import com.Dto.AllSupervisorInfoDto;
import com.Dto.CounselorToAddDto;
import com.common.Result;
import com.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@CrossOrigin
@RequestMapping("Admins")
public class AdminController {
    @Autowired
    private AdminService adminService;

    /**禁用用户
     */
    @PutMapping("disableUsers")
    public Result<Boolean> disableUsers(@RequestParam("userId") Integer userId){

        Result<Boolean> disableUsersResult = new Result<>();
        try{
            Boolean result = adminService.disableUserById(userId);
            disableUsersResult.setSuc(result);
        }catch (Exception e){
            log.error("获取失败：{}",e.getMessage());
            disableUsersResult.setFail("获取失败");
        }
        return disableUsersResult;

    }

    /**解除禁用
     */
    @PutMapping("enableUsers")
    public Result<Boolean> enableUsers(@RequestParam("userId") Integer userId){

        Result<Boolean> enableUsersResult = new Result<>();
        try{
            Boolean result = adminService.enableUserById(userId);
            enableUsersResult.setSuc(result);
        }catch (Exception e){
            log.error("获取失败：{}",e.getMessage());
            enableUsersResult.setFail("获取失败");
        }
        return enableUsersResult;

    }

    /**查询所有督导姓名，督导id, 督导名下的咨询师姓名，援助总次数，援助总时长，本月排班日期
     *
     * @return
     */

     @GetMapping("getAllSupervisor")
    public Result<List<AllSupervisorInfoDto>> getAllSupervisor(){

        Result<List<AllSupervisorInfoDto>>  getAllSupervisorResult = new Result<>();
        try{
            List<AllSupervisorInfoDto> result = adminService.findAllSupervisorInfo();
            getAllSupervisorResult.setSuc(result);
        }catch (Exception e){
            log.error("获取失败：{}",e.getMessage());
            getAllSupervisorResult.setFail("获取失败");
        }
        return getAllSupervisorResult;


    }

    /**查看所有咨询师信息，包括咨询师姓名, 咨询师id，咨询师绑定的督导姓名，咨询总次数，咨询总时长，本月排班日期
     *
     * @return
     */
    @GetMapping("getAllCounselor")
    public Result<List<AllCounselorInfoDto>> getAllCounselor(){

        Result<List<AllCounselorInfoDto>> getAllCounselorResult = new Result<>();

        try{
            List<AllCounselorInfoDto> result = adminService.findAllCounselorInfo();
            getAllCounselorResult.setSuc(result);
        }catch (Exception e){
            log.error("获取失败：{}",e.getMessage());
            getAllCounselorResult.setFail("获取失败");
        }
            return getAllCounselorResult;

    }

    /**添加咨询师
     *咨询师姓名 性别 年龄  身份证号码 电话号码 邮箱 绑定的督导 用户名 密码 职称 工作单位
     */
    @PostMapping("addCounselor")
    public Result<Boolean> addCounselor(@RequestBody CounselorToAddDto counselor
                                        ){
        Result<Boolean> addCounselorResult = new Result<>();
        try{
            Boolean result = adminService.addCounselor(counselor);
            addCounselorResult.setSuc(result);
        }catch (Exception e){
            log.error("获取失败：{}",e.getMessage());
            addCounselorResult.setFail("获取失败");
        }
        return addCounselorResult;


    }
    /** 绑定咨询师和督导
     *
     */
    @PostMapping("addRelationship")
    public Result<Boolean> addRelationship(@RequestParam("counselorId") Integer counselorUserId, @RequestParam ("supervisorId")Integer supervisorUserId
    ) {
        Result<Boolean> addRelationshipResult = new Result<>();
        try {
            Boolean result = adminService.addRelationship(counselorUserId, supervisorUserId);
            addRelationshipResult.setSuc(result);
        } catch (Exception e) {
            log.error("获取失败：{}", e.getMessage());
            addRelationshipResult.setFail("获取失败");
        }
        return addRelationshipResult;
    }
}
